<?php
// Obtener contactos activos
$contactos = Contacto::model()->activos()->de_cuenta($model->id)->ordenPorNombre()->findAll();
Util::tsRegisterAssetJs('contactos.js');
?>
<div class="widget green">
    <div class="widget-title">
        <h4><i class="icon-group"></i> Contactos</h4>
        <span class="tools">
            <a href="javascript:;" class="icon-chevron-down"></a>
            <a href="javascript:;" class="icon-remove"></a>
        </span>
    </div>
    <div class="widget-body">
        <div class="row-fluid">
            <?php if ($contactos): ?>
                <div style='overflow:auto'> 
                    <?php
                    $this->widget('ext.selgridview.BootSelGridView', array(
                        'id' => 'contacto-grid',
                        'afterAjaxUpdate' => "function(id,data){AjaxActualizarActividades();}",
                        'type' => 'striped bordered hover advance',
                        'dataProvider' => new CArrayDataProvider($contactos, array('pagination' => array('pageSize' => 5))),
                        'selectableRows' => 2,
                        'columns' => array(
                            array(
                                'name' => 'Nombre',
                                'value' => 'CHtml::link($data->nombre_completo, Yii::app()->createUrl("crm/contacto/view",array("id"=>$data->id)))',
                                'type' => 'raw',
                            ),
                            array(
                                'class' => 'CButtonColumn',
                                'template' => '{sms} {email} {llamada} {update} {delete}',
                                'buttons' => array(
                                    'llamada' => array(
                                        'label' => '<button class="btn btn-warning"><i class="icon-phone"></i></button>',
                                        'options' => array('title' => 'Registrar llamada'),
                                        'imageUrl' => false,
                                        'url' => '$data->id',
                                        'click' => 'function() {crearLlamada($(this).attr("href")); return false;}',
                                        'visible' => 'Util::checkAccess(array("action_llamada_cargarFormularioLlamadaSaliente"))',
                                    ),
                                    'sms' => array(
                                        'label' => '<button class="btn btn-success"><i class="icon-comments"></i></button>',
                                        'options' => array('title' => 'Enviar SMS'),
                                        'imageUrl' => false,
                                        'url' => '$data->id',
                                        'click' => 'function() {enviarSmsSolo($(this).attr("href")); return false;}',
                                        'visible' => 'Util::checkAccess(array("action_sms_cargarFormularioSms"))',
                                    ),
                                    'email' => array(
                                        'label' => '<button class="btn btn-inverse"><i class="icon-envelope"></i></button>',
                                        'options' => array('title' => 'Enviar Correo Electrónico'),
                                        'imageUrl' => false,
                                        'url' => '$data->id',
                                        'click' => 'function() {enviarMailSolo($(this).attr("href"),"contacto/admin"); return false;}',
                                        'visible' => 'Util::checkAccess(array("action_mail_cargarFormularioMail"))',
                                    ),
                                    'update' => array(
                                        'label' => '<button class="btn btn-primary"><i class="icon-pencil"></i></button>',
                                        'options' => array('title' => 'Actualizar'),
                                        'url' => 'Yii::app()->createUrl("crm/contacto/update", array("id"=>$data->id))',
                                        'imageUrl' => false,
                                        'visible' => 'Util::checkAccess(array("action_contacto_update"))',
                                    ),
                                    'delete' => array(
                                        'label' => '<button class="btn btn-danger"><i class="icon-trash"></i></button>',
                                        'options' => array('title' => 'Eliminar'),
                                        'url' => 'Yii::app()->createUrl("crm/contacto/delete", array("id"=>$data->id))',
                                        'imageUrl' => false,
                                        'visible' => 'Util::checkAccess(array("action_contacto_delete"))',
                                    ),
                                ),
                                'htmlOptions' => array(
                                    'width' => '220px'
                                )
                            ),
                        ),
                    ));
                    ?>
                </div> 
                <br>

            <?php endif; ?>

            <?php
            Util::checkAccess(array('action_contacto_createModal')) ?
                            $this->widget(
                                    'bootstrap.widgets.TbButton', array(
                                'id' => 'add-contact',
                                'label' => ($contactos ? '' : '<br>') . 'Agregar Contacto',
                                'encodeLabel' => false,
                                'icon' => $contactos ? 'plus-sign' : 'user',
                                'htmlOptions' => array(
                                    'onClick' => 'js:viewModal("crm/contacto/create/id_cuenta/' . $model->id . '",function(){'
                                    . 'maskAttributes();})',
                                    'class' => $contactos ? '' : 'empty-portlet',
                                ),
                                    )
                            ) : '';
            ?>

        </div>
    </div>
</div>